<template>
    <div class="hospital">
        <!-- 左侧导航区 -->
        <div class="menu">
            <div class="top">
                <el-icon>
                    <HomeFilled />
                </el-icon>
                <p> / 医院信息</p>
            </div>
            <el-menu :default-active="$route.path" class="el-menu-vertical-demo">
                <el-menu-item index="/hospital/register" @click="changeActive('/hospital/register')">
                    <el-icon>
                        <Setting />
                    </el-icon>
                    <span>预约挂号</span>
                </el-menu-item>
                <el-menu-item index="/hospital/detail" @click="changeActive('/hospital/detail')">
                    <el-icon>
                        <Document />
                    </el-icon>
                    <span>医院详情</span>
                </el-menu-item>
                <el-menu-item index="/hospital/notice" @click="changeActive('/hospital/notice')">
                    <el-icon>
                        <IconMenu />
                    </el-icon>
                    <span>预约须知</span>
                </el-menu-item>
                <el-menu-item index="/hospital/close" @click="changeActive('/hospital/close')">
                    <el-icon>
                        <InfoFilled />
                    </el-icon>
                    <span>停诊信息</span>
                </el-menu-item>
                <el-menu-item index="/hospital/search" @click="changeActive('/hospital/search')">
                    <el-icon>
                        <Search />
                    </el-icon>
                    <span>查询/取消</span>
                </el-menu-item>
            </el-menu>
        </div>
        <!-- 右侧内容展示区 -->
        <div class="content">
            <!-- 子组件展示区 -->
            <router-view></router-view>
        </div>
    </div>
</template>
    
<script setup lang='ts'>
// 引入左侧菜单的图标
import {
    HomeFilled,
    Document,
    Menu as IconMenu,
    Setting,
    InfoFilled,
    Search
} from '@element-plus/icons-vue'
// 引入路由器
import { useRouter, useRoute } from 'vue-router'
// 引入状态数据
import useDetailStore from "@/store/modules/hospitalDetail"

// 引入组合式 api 
import { onMounted } from 'vue';

// 创建一个路由器
let $router = useRouter();
// 获取当前路由
let $route = useRoute();
// 获取仓库对象
let detailStore = useDetailStore();

// 点击左侧菜单的回调
const changeActive = (path: string) => {
    $router.replace({
        path,
        query: { hoscode: $route.query.hoscode }
    });

}

// 组件挂载完毕后，通知仓库发请求将获取的数据储存在 state 中
onMounted(() => {
    // 通知调用医院详情数据
    detailStore.getHospital($route.query.hoscode as string);
    // 通知调用医院科室数据
    detailStore.getDepartment($route.query.hoscode as string);
})
</script>

<style scoped lang="scss">
.hospital {
    display: flex;

    .menu {
        flex: 2;
        display: flex;
        flex-direction: column;
        align-items: center;

        .top {
            display: flex;
            color: #7f7f7f;
        }
    }

    .content {
        flex: 8;
    }
}
</style>